var shu = 0;
var 验证码;
var 验证码a;
var 验证次数 = 0;
var 时间;
var 时间2;
function yanzheng() {
    验证次数++;
    var a = Math.random().toFixed(6).slice(-6);
    验证码 = hex_md5(str_md5(a) + storage[0].md5);
    document.getElementById('yanzheng').innerHTML = a;
    验证码a = a;
    document.getElementById('yzm').value = 验证码a;
    // document.getElementById('yzm').value = "";
    document.getElementById("yzm").focus();
    // console.log(时间 + "验证码第 " + 验证次数 + " 次,验证码为: " + 验证码a + " 加密后的验证码为：" + 验证码);
}

function shijian() {
    document.onload = shijianhanshu();
    document.onload = qianbaoshengyu();
    window.onload = jiezhang();
    setTimeout('shijian()', 100);
}
function shijianhanshu() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var dayinmonth = date.getDate();
    var hour = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    var currentWeek = "星期" + "日一二三四五六".charAt(new Date().getDay());
    if (month < 10) {
        month = "0" + month;
    } if (dayinmonth < 10) {
        dayinmonth = "0" + dayinmonth;
    } if (hour < 10) {
        hour = "0" + hour;
    } if (minutes < 10) {
        minutes = "0" + minutes;
    } if (seconds < 10) {
        seconds = "0" + seconds;
    }
    时间 = year + "-" + month + "-" + dayinmonth + " " + hour + ":" + minutes + ":" + seconds + " " + currentWeek + " ";
    时间2 = year + "-" + month + "-" + dayinmonth + " " + hour + ":" + minutes + ":" + seconds;
    $("#dqshijian").html("当前时间: " + 时间);
}
function qianbaoshengyu() {
    let num = /^-?\d+$/;
    if (感谢您曾经来过 == Infinity) {
        document.getElementById("钱包").innerHTML = "钱包剩余: <a href='JavaScript:;'>" + "∞" + "</a> ¥";
    } else if (感谢您曾经来过 == -Infinity) {
        document.getElementById("钱包").innerHTML = "钱包剩余: <a href='JavaScript:;'>" + "-∞" + "</a> ¥";
    } else if (num.test(感谢您曾经来过)) {
        document.getElementById("钱包").innerHTML = "钱包剩余: <a href='JavaScript:;'>" + 感谢您曾经来过 + "</a> ¥";
    } else {
        document.getElementById("钱包").innerHTML = "<a href='JavaScript:;'>" + "金额出错请检查是否有误<br/>当前值为: " + 感谢您曾经来过 + "</a>";
    }
}
function yanzheng验证码() {
    var username = escape(escape(escape(document.getElementById("username22").value)));
    var password = str_md5(b64_md5(hex_md5(document.getElementById("password22").value)));
    var ccc = hex_md5(str_md5(document.getElementById('yzm').value) + storage[0].md5);
    if (ccc == 验证码) {
        accountAll.push({
            'username': username,
            'passwd': password
        })
        goumaijieguo = "注册成功";
        window.onload = chenggong2();
        console.log(时间 + '注册成功');
    } else {
        goumaijieguo = "请输入正确的验证码";
        window.onload = chenggong2();
    }
}

function quanbu2() { //登陆判断
    var username = escape(escape(escape(document.getElementById("username22").value)));
    var unusername = unescape(unescape(unescape(username)));
    var password = str_md5(b64_md5(hex_md5(document.getElementById("password22").value)));
    var account = accountAll.filter(function (e) {
        return e.username == username
    })[0]; // 筛选账号返回数组，不存在则返回空数组
    if ($("#username22").val().length < 6 || $("#username22").val().length > 12) {
        qrgm[0].username = "";
        qrgm[0].password = "";
        qrgm[0].value = "";
        $("#yzusername").html("<a href='JavaScript:;' style='color: red;'>用户名长度应为6-12个字符");
        goumaijieguo = "用户名长度应为6~12位字符";
        window.onload = chenggong2();
    } else if ($("#password22").val().length < 6 || $("#password22").val().length > 12) {
        qrgm[0].username = "";
        qrgm[0].password = "";
        qrgm[0].value = "";
        $("yzpassword").html("<a href='JavaScript:;' style='color: red;'>用户名长度应为6-12个字符");
        goumaijieguo = "密码长度应为6~12位字符";
        window.onload = chenggong2();
    } else {
        if (!account) {
            qrgm[0].username = "";
            qrgm[0].password = "";
            document.getElementById("span").innerHTML = zhuang;
            document.getElementById("span2").innerHTML = deng;
            document.getElementById("erpassword22").value = "登录";
            感谢您曾经来过 = 0;
            goumaijieguo = "账号或密码输入错误";
            window.onload = chenggong2();
        } else if (account.username == username && account.passwd == password) {
            var ccc = hex_md5(str_md5(document.getElementById('yzm').value) + storage[0].md5);
            if (ccc == 验证码) {
                qrgm[0].username = username;
                qrgm[0].password = password;
                document.getElementById("span").innerHTML = "欢迎用户:  ";
                document.getElementById("span2").innerHTML = unusername;
                document.getElementById("span3").innerHTML = "  再次遇见您真好~";
                $("#yin").fadeOut();
                $(".shadow2").fadeOut();
                document.getElementById("erpassword22").value = "退出";
                console.log(时间 + "登录成功");
                window.onload = yanzheng();
            } else {
                qrgm[0].username = ""; qrgm[0].password = "";
                goumaijieguo = "请输入正确的验证码";
                window.onload = chenggong2();
                document.getElementById("erpassword22").value = "登录";
                document.getElementById("span2").innerHTML = "正在登录中";
            }
        } else {
            qrgm[0].username = "";
            qrgm[0].password = "";
            document.getElementById("span").innerHTML = zhuang;
            document.getElementById("span2").innerHTML = deng;
            document.getElementById("erpassword22").value = "登录";
            goumaijieguo = "账号或密码输入错误";
            window.onload = chenggong2();
        }
    }
}
var zhuang = "当前状态:"
var deng = "未登录";
function szmm() {
    if (document.getElementById("yin").style.display == "none") {
        document.getElementById("erpassword22").value = "取消登录";
        document.getElementById("span2").innerHTML = "正在登录中";
        document.getElementById("span3").innerHTML = "";
        $(".shadow2").fadeIn();
        $("#yin").fadeIn();
    } else {
        document.getElementById("span").innerHTML = zhuang;
        document.getElementById("span2").innerHTML = deng;
        $(".shadow2").fadeOut();
        $("#yin").fadeOut();
        document.getElementById("erpassword22").value = "登录";
        window.onload = yanzheng();
    }
}
var qrgm = [{
    value: '',
    username: '',
    password: '',
    yingfu: '0',
}];
$(function () {
    $("body").attr("id", "weihu");
    window.onload = shijian();
    window.onload = yanzheng();
    document.getElementById("span").innerHTML = zhuang;
    document.getElementById("span2").innerHTML = deng;
    document.getElementById("span3").innerHTML = "";
    document.getElementById("username22").value = "感谢您曾经来过";
    document.getElementById("password22").value = "123456";
    document.getElementById("yzm").value = 验证码a;
    window.onload = quanbu2();
    $("#x").click(function () {
        window.onload = szmm();
    })
    $("#erpassword22").click(function () {
        window.onload = szmm();
    })
    $("#zhuce").click(function () {
        var username = escape(escape(escape(document.getElementById("username22").value)));
        var account = accountAll.filter(function (e) {
            return e.username == username
        })[0];
        if ($("#username22").val().length < 6 || $("#username22").val().length > 12) {
            $("#yzusername").html("<a href='JavaScript:;' style='color: red;'>用户名长度应为6~12个字符");
            goumaijieguo = "用户名长度应为6~12位字符";
            window.onload = chenggong2();
        } else if ($("#password22").val().length < 6 || $("#password22").val().length > 12) {
            $("yzpassword").html("<a href='JavaScript:;' style='color: red;'>密码长度应为6~12个字符");
            goumaijieguo = "密码长度应为6~12位字符";
            window.onload = chenggong2();
        } else {
            if (!account) {
                window.onload = yanzheng验证码();
            } else if (account.username == username) {
                goumaijieguo = "用户名 " + $("#username22").val() + " 已经被人抢先一步啦";
                window.onload = chenggong2();
            } else {
                window.onload = yanzheng验证码();
            }
        }
    })
    $("#username22").on("input", function () {
        if ($("#username22").val().length < 6) {
            $("#yzusername").html("<a href='JavaScript:;' style='color: red;'>用户名长度应为6-12个字符");
        } else {
            $("#yzusername").html("<a href='JavaScript:;' style='color: blue;'>用户名格式正确");
        }
    })
    $("#password22").on("input", function () {
        if ($("#password22").val().length < 6 || $("#password22").val().length > 12) {
            $("#yzpassword").html("<a href='JavaScript:;' style='color: red;'>密码长度应为6-12个字符");
        } else {
            $("#yzpassword").html("<a href='JavaScript:;' style='color: blue;'>密码格式正确");
        }
    })
    $("#jine").html("¥ " + qrgm[0].yingfu);
    $(document).on("input", "#srpassword", function () {
        if ($("#srpassword").val().length < 6 || $("#srpassword").val().length > 12) {
            $("#yzpassword2").html("密码长度应为6~12个字符");
            $("#yzpassword2").css("color", "red");
            $("#srpassword").css("border", "2px solid red");
        } else {
            $("#yzpassword2").html("密码格式正确");
            $("#yzpassword2").css("color", "blue");
            $("#srpassword").css("border", "2px solid #00ffe7");
        }
    })
    $(document).on("click", "#password #quxiao", function () {
        $("#password").fadeOut();
        $("#tooltip").fadeIn();
        $("#password").html(begin2)
    })
})